<template>
  <div class="dashboard-editor-container">
    <div class=" clearfix">
      <pan-thumb :image="avatar" style="float: left">
        你的权限:
        <span v-for="item in roles" :key="item" class="pan-info-roles">{{ item }}</span>
      </pan-thumb>
      <github-corner style="position: absolute; top: 0px; border: 0; right: 0;" />
      <div class="info-container">
        <span class="display_name">{{ name }}</span>
        <span style="font-size:20px;padding-top:20px;display:inline-block;">欢迎使用</span>
      </div>

      <panel-group :is-admin="false" @handleSetLineChartData="handleSetLineChartData" />

      <el-row style="background:#fff;padding:16px 16px 0;margin-bottom:32px;">
        <line-chart :chart-data="currentLineData" :title="currentLineTitle" />
      </el-row>
    </div>
    <div>
      <img :src="emptyGif" class="emptyGif">
    </div>
  </div>
</template>

<script>
import { mapGetters } from 'vuex'
import PanThumb from '@/components/PanThumb'
import GithubCorner from '@/components/GithubCorner'
import LineChart from '../admin/components/LineChart'
import PanelGroup from '../admin/components/PanelGroup'
import { dashboardMerchant } from '@/api/statist'

export default {
  name: 'DashboardEditor',
  components: {
    PanThumb,
    GithubCorner,
    LineChart,
    PanelGroup
  },
  data() {
    const currentLintChartData = []
    for (let i = 0; i < 14; ++i) {
      currentLintChartData.push(Math.floor(Math.random() * 100))
    }
    return {
      emptyGif: 'https://wpimg.wallstcn.com/0e03b7da-db9e-4819-ba10-9016ddfdaed3',
      currentLineData: currentLintChartData,
      lineChartData: [],
      currentLineTitle: '产品数'
    }
  },
  computed: {
    ...mapGetters([
      'name',
      'avatar',
      'roles'
    ])
  },
  created() {
    dashboardMerchant().then(res => {
      this.lineChartData = res
      this.currentLineTitle = '产品数'
      this.currentLineData = this.lineChartData.product_increased_two_weeks
    })
  },
  methods: {
    handleSetLineChartData(type) {
      switch (type) {
        case 'product': {
          this.currentLineData = this.lineChartData.product_increased_two_weeks
          this.currentLineTitle = '产品数'
          break
        }
        case 'order': {
          this.currentLineData = this.lineChartData.order_increased_two_weeks
          this.currentLineTitle = '订单数'
          break
        }
      }
    }
  }
}
</script>

<style lang="scss" scoped>
  .emptyGif {
    display: block;
    width: 45%;
    margin: 0 auto;
  }

  .dashboard-editor-container {
    background-color: #e3e3e3;
    min-height: 100vh;
    padding: 50px 60px 0px;
    .pan-info-roles {
      font-size: 12px;
      font-weight: 700;
      color: #333;
      display: block;
    }
    .info-container {
      position: relative;
      margin-left: 190px;
      height: 150px;
      line-height: 200px;
      .display_name {
        font-size: 48px;
        line-height: 48px;
        color: #212121;
        position: absolute;
        top: 25px;
      }
    }
  }
</style>
